package com.ericsson.rm.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ericsson.rm.dao.ProjectResourceDao;
import com.ericsson.rm.dao.ResourceDetailDao;
import com.ericsson.rm.dao.ResourceSkillDao;
import com.ericsson.rm.dao.RoleDetailDao;
import com.ericsson.rm.dao.SkillDetailDao;
import com.ericsson.rm.dao.repository.ResourceDetailDaoRepository;
import com.ericsson.rm.dao.repository.RoleDetailDaoRepository;
import com.ericsson.rm.dao.repository.SkillDetailDaoRepository;
import com.ericsson.rm.model.ResourceDetail;
import com.ericsson.rm.model.RoleDetail;
import com.ericsson.rm.model.SkillDetail;
import com.ericsson.rm.response.ResourceProjectResponse;
import com.ericsson.rm.response.RoleDetailResponse;
import com.ericsson.rm.response.SkillDetailResponse;

@Service
public class SkillRoleResourceServiceImpl implements SkillRoleResourceService {

/*	@Autowired
	private SkillDetailDao skillDetailDao;

	@Autowired
	private RoleDetailDao roleDetailDao;
	
	@Autowired
	private ProjectResourceDao projectResourceDao;
	
	@Autowired
	private ResourceSkillDao resourceSkillDao;
	
	@Autowired
	private ResourceDetailDao resourceDetailDao;*/
	
	@Autowired
	private ResourceDetailDaoRepository resourceDetailRepository;
	
	@Autowired
	private RoleDetailDaoRepository roleDetailRepository;
	
	@Autowired
	private SkillDetailDaoRepository skillDetailRepository;

	public List<SkillDetailResponse> fetchSkillDetail() {
		
		List<SkillDetailResponse> skillDetailResponse = null;
		
		
		//List<SkillDetail> skillDetail = skillDetailDao.fetchAllSkillDetail();
		List<SkillDetail> skillDetail = skillDetailRepository.findAll();
		
		if (null != skillDetail && skillDetail.size() != 0) {
			skillDetailResponse = new ArrayList<SkillDetailResponse>(skillDetail.size());
		}
		for (int i = 0; i < skillDetail.size(); i++) {			
			SkillDetailResponse response = new SkillDetailResponse();
			BeanUtils.copyProperties(skillDetail.get(i), response);
			skillDetailResponse.add(response);
			
			
			/*skillId = skillDetail.get(i).getSkillId();
			skillDescription = skillDetail.get(i).getSkillDescription();
			skillType = skillDetail.get(i).getSkillType();
			skillDetailObject.setSkillId(skillId);
			skillDetailObject.setSkillDescription(skillDescription);
			skillDetailObject.setSkillType(skillType);
			skillDetailResponse.add(skillDetailObject);*/

		}
		return skillDetailResponse;

	}

	
	/*public String fetchSkillIdBySkillDesc(String skillId) {
		return skillDetailDao.fetchSkillIdBySkillDesc(skillId);
	}*/

	@Override
	public List<RoleDetailResponse> fetchRoleDetail() {
		List<RoleDetailResponse> roleDetailResponse = null;
		
		//List<RoleDetail> roleDetail = roleDetailDao.fetchRoleDetail();
		List<RoleDetail> roleDetail =  roleDetailRepository.findAll();
		
		if (null != roleDetail && roleDetail.size() != 0) {
			roleDetailResponse = new ArrayList<RoleDetailResponse>(
					roleDetail.size());

			for (int i = 0; i < roleDetail.size(); i++) {
				RoleDetailResponse response = new RoleDetailResponse();
				BeanUtils.copyProperties(roleDetail.get(i), response);
				roleDetailResponse.add(response);
			}
		}

		return roleDetailResponse;
	}

	
	/*public String fetchRoleIdByRoleName(String roleName) {
		
		return roleDetailDao.fetchRoleIdByRoleName(roleName);
	}
	
	public List<ResourceProjectDetail> fetchResourceProjectInDateRange(String startDate,String endDate) {		
		List<ResourceProjectDetail> resourceProjectDetail = projectResourceDao.fetchResourceProjectInDateRange(startDate, endDate);
		return null;
	}*/
	
	public List<ResourceProjectResponse> fetchResourceDetailWithRoleAndSkill(String jobStage,String skillId) {
		
		//List<String> resourceIdList = resourceSkillDao.fetchResourceIdBySkillId(skillId);	
		
		List<ResourceProjectResponse>  resourceProjectResponse = resourceDetailRepository.searchResourceByJobStageAndSkillId(jobStage, skillId);
		System.out.println(resourceProjectResponse.size());
		return resourceProjectResponse;
		
	}

}
